/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SearchBillingMore.java
 *
 * Created on Aug 7, 2012, 2:41:26 PM
 */

package Model.dialog;

import DataBase.DBManagerment;
import Processing.PikaDate;
import java.sql.Connection;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author Admin
 */
public class dlgSearchTestByCost extends javax.swing.JDialog {

    /** Creates new form SearchBillingMore */
    public dlgSearchTestByCost(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btgPaid = new javax.swing.ButtonGroup();
        pnlCenter = new javax.swing.JPanel();
        cbbCostThan1 = new javax.swing.JComboBox();
        cbbCostThan2 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        txtCost1 = new javax.swing.JTextField();
        txtCost2 = new javax.swing.JTextField();
        pnlBootom = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Search Test By Cost");
        setResizable(false);

        cbbCostThan1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "=", ">", ">=", "<", "<=" }));
        cbbCostThan1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbCostThan1ItemStateChanged(evt);
            }
        });

        cbbCostThan2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No", "<", "<=" }));
        cbbCostThan2.setEnabled(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText("Choose Cost");

        javax.swing.GroupLayout pnlCenterLayout = new javax.swing.GroupLayout(pnlCenter);
        pnlCenter.setLayout(pnlCenterLayout);
        pnlCenterLayout.setHorizontalGroup(
            pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCenterLayout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cbbCostThan2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbCostThan1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtCost2)
                    .addComponent(txtCost1, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))
                .addContainerGap(44, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlCenterLayout.createSequentialGroup()
                .addGap(71, 71, 71)
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(68, 68, 68))
        );
        pnlCenterLayout.setVerticalGroup(
            pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCenterLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbbCostThan1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCost1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbbCostThan2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCost2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        getContentPane().add(pnlCenter, java.awt.BorderLayout.CENTER);

        pnlBootom.setPreferredSize(new java.awt.Dimension(226, 40));

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cancel");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlBootomLayout = new javax.swing.GroupLayout(pnlBootom);
        pnlBootom.setLayout(pnlBootomLayout);
        pnlBootomLayout.setHorizontalGroup(
            pnlBootomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBootomLayout.createSequentialGroup()
                .addContainerGap(49, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2)
                .addGap(40, 40, 40))
        );
        pnlBootomLayout.setVerticalGroup(
            pnlBootomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBootomLayout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addGroup(pnlBootomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(pnlBootom, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cbbCostThan1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbCostThan1ItemStateChanged
        // TODO add your handling code here:
        if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
            if (cbbCostThan1.getSelectedItem().equals("=") || cbbCostThan1.getSelectedItem().equals("<") || cbbCostThan1.getSelectedItem().equals("<=")) {
                cbbCostThan2.setEnabled(false);

                cbbCostThan2.setSelectedItem("No");
            }else{
                cbbCostThan2.setEnabled(true);
            }
        }
    }//GEN-LAST:event_cbbCostThan1ItemStateChanged

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:        

        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:

        if (cbbCostThan1.getSelectedItem().equals("=")) {
            // Lấy một chuỗi dạng: "[Cost] = 10"
            search = "[Cost] = " + txtCost1.getText();

        } else if (cbbCostThan1.getSelectedItem().equals("<")) {
            // Lấy một chuỗi dạng: "[Cost] < 10'"
            search = "[Cost] < " + txtCost1.getText();

        } else if (cbbCostThan1.getSelectedItem().equals("<=")) {
            // Lấy một chuỗi dạng: "[Cost] <= 10"
            search = "[Cost] <= " + txtCost1.getText();

        } else if (cbbCostThan1.getSelectedItem().equals(">")) {
            // Lấy một chuỗi dạng: "[Cost] > 10"
            search = "[Cost] > " + txtCost1.getText();

            if (cbbCostThan2.getSelectedItem().equals("<")) {
                // Lấy một chuỗi dạng: "[Cost] <= '2012-7-8'" với ngày tháng lấy từ combobox
                search = "[Cost] > " + txtCost1.getText() + " and " + "[Cost] < " + txtCost2.getText();

            } else if (cbbCostThan2.getSelectedItem().equals("<=")) {
                // Lấy một chuỗi dạng: "[Cost] <= '2012-7-8'" với ngày tháng lấy từ combobox
                search = "[Cost] > " + txtCost1.getText() + " and " + "[Cost] <= " + txtCost2.getText();

            }
        } else if (cbbCostThan1.getSelectedItem().equals(">=")) {
            // Lấy một chuỗi dạng: "[Cost] > '2012-7-8'" với ngày tháng lấy từ combobox
            search = "[Cost] >= " + txtCost1.getText();


            if (cbbCostThan2.getSelectedItem().equals("<")) {
                // Lấy một chuỗi dạng: "[Cost] <= '2012-7-8'" với ngày tháng lấy từ combobox
                search = "[Cost] >= " + txtCost1.getText() + " and " + "[Cost] < " + txtCost2.getText();

            } else if (cbbCostThan2.getSelectedItem().equals("<=")) {
                // Lấy một chuỗi dạng: "[Cost] <= '2012-7-8'" với ngày tháng lấy từ combobox
                search = "[Cost] >= " + txtCost1.getText() + " and " + "[Cost] <= " + txtCost2.getText();

            }
        }      
        
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                dlgSearchTestByCost dialog = new dlgSearchTestByCost(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    /**
     * Đây là list chứa chuỗi tìm kiếm
     */
    private String search;

    /**
     * Method này trả về list chuỗi tìm kiếm
     * @return list chuỗi tìm kiếm
     */
    public String getSearch() {
        return search;
    }

    private DBManagerment db = new DBManagerment();
    private Connection conn;


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup btgPaid;
    private javax.swing.JComboBox cbbCostThan1;
    private javax.swing.JComboBox cbbCostThan2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel pnlBootom;
    private javax.swing.JPanel pnlCenter;
    private javax.swing.JTextField txtCost1;
    private javax.swing.JTextField txtCost2;
    // End of variables declaration//GEN-END:variables

}
